layui.use(['form', 'jquery', 'layer'], function () {
    var layer = layui.layer;
    $("#login").click(function () {
        let username = $("#username").val();
        let password = $("#password").val();
        let data = {"code": username, "password": password};
        if (username != "" && password != "") {
            let result = ajaxModel("/user/login","post",data);
            console.log(result);
            if (result.code == 200) {
                layer.alert(result.message, {
                    icon: 1
                }, function () {
                    sessionStorage.setItem("userInfo",JSON.stringify(result.data.userInfo));
                    sessionStorage.setItem("user_code",result.data.userInfo.code);
                    $.cookie("token", result.data.tokenHead + " " + result.data.access_token);
                    window.location.href = "index.html";
                    layer.close();
                });
            } else
                layer.msg(result.message);
        } else {
            layer.msg("用户名和密码不能为空");
            $("#username").focus();
        }

    })
    $("#register").click(function () {
        window.location.href = "register.html";
    })
});